package com.chenyue.cm.common.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.chenyue.cm.base.dao.LcBaseMapper;
import com.chenyue.cm.base.service.BaseServiceImpl;
import com.chenyue.cm.common.dao.JdBannerMapper;
import com.chenyue.cm.common.domain.JdBanner;
import com.chenyue.cm.common.service.JdBannerService;
import com.chenyue.cm.match.dao.PublicAreaMapper;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;


/**
 * @author chenyue-cm
 */
@Service(value = "JdBannerService")
public class JdBannerServiceImpl extends BaseServiceImpl<JdBanner> implements JdBannerService {

    private final JdBannerMapper jdBannerMapper;

    private final PublicAreaMapper publicAreaMapper;

    public JdBannerServiceImpl(
            @Qualifier("jdBannerMapper") JdBannerMapper jdBannerMapper,
            @Qualifier("publicAreaMapper") PublicAreaMapper publicAreaMapper
    ) {
        this.jdBannerMapper = jdBannerMapper;
        this.publicAreaMapper = publicAreaMapper;
    }

    @Override
    @Resource(name = "jdBannerMapper")
    public void setBaseMapper(LcBaseMapper<JdBanner, Serializable> baseMapper) {
        this.baseMapper = baseMapper;
    }

    @Override
    public List<JdBanner> getCityBanner(Integer cityCode) {
        LambdaQueryWrapper<JdBanner> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(JdBanner::getIsShow, 1)
                .eq(JdBanner::getType, 3);
        if (cityCode != null && cityCode > 0) {
            wrapper.eq(JdBanner::getCity, cityCode);
        }
        wrapper.or().eq(JdBanner::getCity, "");
        return jdBannerMapper.selectList(wrapper);
    }

    @Override
    public List<JdBanner> getGuidePage() {
        LambdaQueryWrapper<JdBanner> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(JdBanner::getIsShow, 1)
                .eq(JdBanner::getType, 1);
        return jdBannerMapper.selectList(wrapper);
    }

    @Override
    public List<JdBanner> getStartPage() {
        LambdaQueryWrapper<JdBanner> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(JdBanner::getIsShow, 1)
                .eq(JdBanner::getType, 2);
        return jdBannerMapper.selectList(wrapper);
    }
}
